package com.example.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * interceptor 类的描述信息
 *
 *   SpringBoot 自带的拦截器 interceptor
 *
 * @author 12427
 * @since 2025/6/8 12:09
 */
@Component//交给容器启动
@Slf4j
public class DomeInterceptor implements HandlerInterceptor {
//    @Override//目标资源前执行  true  放行 false  拦截
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("preHandle  开始拦截");
        return true;
    }

    @Override///目标资源后执行
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.info("postHandle  后");
    }

    @Override//响应结束执行
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.info("afterCompletion  结束");
    }
}
